﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAPbobsCOM;
using BoAddonBiz_FreightForwarder.BusinessBase;

namespace BoAddonBiz_FreightForwarder
{
    /// <summary>
    /// 制作账单——comment by Webb.Wen
    /// </summary>
    [ControlB1FormAttribute(IsNew = true, FormType = B1FormTypes.ado_AVA_FF_CreateVoucher)]
    public class B1Form_CreateVoucher : SAPBoAddon.B1Form
    {
        public B1Form_CreateVoucher()
        {
            frm_ChooseFormListEvent += new SAPBoAddon.IB1FormEvents.B1ChooseFormListEventEventHandler(B1Form_CreateVoucher_frm_ChooseFormListEvent);
            frm_ItemEvent += new SAPBoAddon.IB1FormEvents.B1ItemEventEventHandler(B1Form_CreateVoucher_frm_ItemEvent);
            frm_FormDataEvent += new SAPBoAddon.IB1FormEvents.B1FormDataEventEventHandler(B1Form_CreateVoucher_frm_FormDataEvent);
        }
        #region 继承至基类
        protected override bool BeforeSaveCheckFormData()
        {
            SAPbouiCOM.Matrix oMtx_1 = this.CurrentForm.Items.Item("mtx_0").Specific;
            SAPbouiCOM.Matrix oMtx_2 = this.CurrentForm.Items.Item("mtx_1").Specific;
            SAPbouiCOM.DBDataSource dbds_1 = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_CCV1");
            SAPbouiCOM.DBDataSource dbds_2 = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_CCV2");
            oMtx_1.FlushToDataSource();
            oMtx_1.FlushToDataSource();
            string Field_Check = string.Empty;
            bool isNothing_Matrix1 = true;
            bool isNothing_Matrix2 = true;
            for (int offSet1 = 0; offSet1 < dbds_1.Size; offSet1++)
            {
                Field_Check = dbds_1.GetValue("U_CardName", offSet1).Trim();
                if (!string.IsNullOrEmpty(Field_Check))
                {
                    isNothing_Matrix1 = false;
                    break;
                }
                else
                {
                    isNothing_Matrix1 = true;
                }
            }
            if (isNothing_Matrix1)
            {
                SBOApp.StatusBar.SetText("结算单位信息缺失.", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                return false;
            }
            for (int offSet2 = 0; offSet2 < dbds_2.Size; offSet2++)
            {
                Field_Check = dbds_2.GetValue("U_CostCode", offSet2).Trim();
                if (!string.IsNullOrEmpty(Field_Check))
                {
                    isNothing_Matrix2 = false;
                    break;
                }
                else
                {
                    isNothing_Matrix2 = true;
                }
            }
            if (isNothing_Matrix2)
            {
                SBOApp.StatusBar.SetText("费用信息缺失.", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                return false;
            }

            return true;
        }

        protected override void FormEditModeChange(SAPBoAddon.frmItemEditMode frmEditMode)
        {
            SAPbouiCOM.DBDataSource odbds = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_OCCV");
            switch (frmEditMode)
            {
                case SAPBoAddon.frmItemEditMode.fe_AddMode:
                    string Operator = Utils.GetCurrentUser().Operator;;
                    odbds.SetValue("U_Operator", odbds.Offset, Operator);
                    odbds.SetValue("U_DocDate", odbds.Offset, DateTime.Now.ToString("yyyyMMdd"));
                    this.Matrix_AutoAddLine();
                    /*使Matrix行可用*/
                    Utils.SetMatrixRowEnable(this.CurrentForm, "mtx_0");
                    Utils.SetMatrixRowEnable(this.CurrentForm, "mtx_1");
                    break;
            }
        }

        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            FormSetting.FormType = B1FormTypes.ado_AVA_FF_CreateVoucher;
            FormSetting.FormFileName = "AVA_FF_CreateVoucherForm.srf";

            #region 配置添加子表的行
            FormSetting.AutoGetObjectNextNumber = true;
            FormSetting.MatrixSetting.MtxUID = "mtx_0";
            FormSetting.MatrixSetting.AutoAddNewLine = true;
            FormSetting.MatrixSetting.AutoLineKeyCol = "col_2";//结算单位
            FormSetting.MatrixSetting.BeforeSaveDeleteNoValueLine = true;
            FormSetting.MatrixSetting.BeforeSaveFixDbDataSourceData = false;
            FormSetting.MatrixSetting.TableKeyField = "VisOrder";
            FormSetting.MatrixSetting.TableVisOrder = "VisOrder";
            FormSetting.MatrixSetting.PrimaryLineCol = "col_f";
            FormSetting.MatrixSetting.TableName = "@AVA_FF_CCV1";
            FormSetting.MatrixSetting.Add();

            FormSetting.MatrixSetting.MtxUID = "mtx_1";
            FormSetting.MatrixSetting.AutoAddNewLine = true;
            FormSetting.MatrixSetting.AutoLineKeyCol = "col_2";//费用编码
            FormSetting.MatrixSetting.BeforeSaveDeleteNoValueLine = true;
            FormSetting.MatrixSetting.BeforeSaveFixDbDataSourceData = false;
            FormSetting.MatrixSetting.TableKeyField = "VisOrder";
            FormSetting.MatrixSetting.TableVisOrder = "VisOrder";
            FormSetting.MatrixSetting.PrimaryLineCol = "col_f";
            FormSetting.MatrixSetting.TableName = "@AVA_FF_CCV2";
            FormSetting.MatrixSetting.Add();
            #endregion

            #region 控件是否可编辑
            //FormSetting.FormModeSetting.StatusItemUID = "7";
            //FormSetting.FormModeSetting.DisableStatus = new string[] { "R", "F", "C" };
            ///*添加单据异常，注释  WangPeng*/
            ////FormSetting.FormModeSetting.itmBrowseModeDisable = new string[] { };
            ////FormSetting.FormModeSetting.itmBrowseModeDisable = Utils.GetFormItems(FormSetting.FormXmlDocument);
            //FormSetting.FormModeSetting.itmFindModeEnable = new string[] { "3", "65" };

            #endregion

        }

        protected override void InitializeForm(SAPBoAddon.B1FormInitializePar InitPar)
        {
            //Utils.InitialMatrixComboBox(this.SBOCompany, this.CurrentForm.Items.Item("mtx_0").Specific, "col_4", "CurrCode", "CurrName", "OCRN", null, null, null);//结算币种
            //Utils.InitialMatrixComboBox(this.SBOCompany, this.CurrentForm.Items.Item("mtx_0").Specific, "col_18", "CurrCode", "CurrName", "OCRN", null, null, null);//源币种

            Utils.ComboBox_InitialItem(SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset), this.CurrentForm.Items.Item("67"), "DocCurrCod", "CurrName", "OCRN");//费用币种
            Utils.InitialMatrixComboBox(this.SBOCompany, this.CurrentForm.Items.Item("mtx_1").Specific, "col_8", "CurrCode", "CurrName", "OCRN", null, null, null);//结算币种

            if (InitPar.FatherFormUID.StartsWith(B1FormTypes.ado_AVA_FF_CreateVoucherList))
            {
                string ListFormUID = InitPar.FatherFormUID;
                SBOApp.Menus.Item("1282").Activate();
                this.AddToParentForm(ListFormUID, Convert.ToInt32(InitPar.KeyValue), InitPar.parObject.ToString());
            }
        }
        #endregion

        #region 事件处理
        void B1Form_CreateVoucher_frm_ChooseFormListEvent(SAPBoAddon.B1AddonBase.B1ChooseFormList pVal, ref bool BubbleEvent)
        {
            SAPbouiCOM.Matrix omtx = default(SAPbouiCOM.Matrix);
            SAPbouiCOM.DBDataSource dbds = default(SAPbouiCOM.DBDataSource);
            SAPbouiCOM.Conditions cons;
            SAPbouiCOM.Condition con;
            SAPbouiCOM.ChooseFromList cfl;
            SAPbobsCOM.Recordset oRst = (SAPbobsCOM.Recordset)SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);

            if (pVal.BeforeAction)
            {
                cfl = this.CurrentForm.ChooseFromLists.Item(pVal.ChooseFromListUID);
                switch (pVal.ChooseFromListUID)
                {
                    //客户编码
                    case "CFL_CardCode":
                    //客户名称
                    case "CFL_CardName":
                        oRst.DoQuery("SELECT U_CardCode FROM [@AVA_FF_OCCT] Where U_Status = 'R'");
                        cons = new SAPbouiCOM.Conditions();
                        for (int i = 0; i < oRst.RecordCount - 1; i++)
                        {
                            con = cons.Add();
                            if (i == 0)
                                con.BracketOpenNum = 1;
                            con.Alias = "CardCode";
                            con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                            con.CondVal = oRst.Fields.Item("U_CardCode").Value;
                            con.Relationship = SAPbouiCOM.BoConditionRelationship.cr_OR;
                            oRst.MoveNext();
                        }
                        if (oRst.RecordCount > 0)
                        {
                            con = cons.Add();
                            con.Alias = "CardCode";
                            con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                            con.CondVal = oRst.Fields.Item("U_CardCode").Value;
                            if (oRst.RecordCount > 1)
                                con.BracketCloseNum = 1;
                            con.Relationship = SAPbouiCOM.BoConditionRelationship.cr_AND;
                        }
                        con = cons.Add();
                        con.Alias = "CardType";
                        con.CondVal = "S";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        string temp = cons.GetAsXML();
                        cfl.SetConditions(cons);
                        break;
                    //结算单位
                    case "CFL_CloseCode":
                    case "CFL_CloseName":
                        //string BillType = SAPBoAddon.B1Assistant.Matrix.GetCellValue(CurrentForm.Items.Item(pVal.ItemUID).Specific, "col_0", pVal.Row);
                        //if (string.IsNullOrEmpty(BillType))
                        //{
                        //    SBOApp.MessageBox("请先选择账单类型是应收还是应付，再选择结算单位！");
                        //    return;
                        //}
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_OCCV");
                        oRst.DoQuery(string.Format(@"SELECT Distinct T1.U_CardCode
                        FROM [@AVA_FF_OCCT] T0
	                    INNER JOIN [@AVA_FF_CCTV] T1 ON T0.DocEntry = T1.DocEntry
                        Where T0.U_Status = 'R' And T0.U_CardCode = N'{0}' ", dbds.GetValue("U_CardCode", dbds.Offset).Trim()));    //And T1.U_BillType = '" + BillType + "'");
                        cons = new SAPbouiCOM.Conditions();
                        for (int i = 0; i < oRst.RecordCount - 1; i++)
                        {
                            con = cons.Add();
                            con.Alias = "CardCode";
                            con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                            con.CondVal = oRst.Fields.Item("U_CardCode").Value;
                            if (i == 0)
                                con.BracketOpenNum = 1;
                            con.Relationship = SAPbouiCOM.BoConditionRelationship.cr_OR;
                            oRst.MoveNext();
                        }
                        if (oRst.RecordCount > 0)
                        {
                            con = cons.Add();
                            con.Alias = "CardCode";
                            con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                            con.CondVal = oRst.Fields.Item("U_CardCode").Value;
                            if (oRst.RecordCount > 1)
                                con.BracketCloseNum = 1;
                            con.Relationship = SAPbouiCOM.BoConditionRelationship.cr_AND;
                        }
                        con = cons.Add();
                        con.Alias = "CardType";
                        con.CondVal = "S";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                }

            }
            else
            {
                switch (pVal.ChooseFromListUID)
                {

                    //客户编码
                    case "CFL_CardCode":
                    case "CFL_CardName":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_OCCV");
                        dbds.SetValue("U_CardCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_CardName", dbds.Offset, pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                        //dbds.SetValue("U_CntctCode", dbds.Offset, pVal.SelectedObjects.GetValue("CntctPrsn", 0).ToString());
                        dynamic Cntct = Utils.GetDefaultContractPerson(SBOCompany, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        if (Cntct != null)
                        {
                            dbds.SetValue("U_CntctCode", dbds.Offset, Cntct.CntctCode);
                            //dbds.SetValue("U_CntctPhone", dbds.Offset, Cntct.Cellolar);
                            //dbds.SetValue("U_CntctFax", dbds.Offset, Cntct.Fax);
                        }
                        break;
                    case "CFL_EmployeeC":
                    case "CFL_EmployeeN":
                        dbds = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_OCCV");
                        dbds.SetValue("U_AuditorMan", dbds.Offset, pVal.SelectedObjects.GetValue("empID", 0).ToString());
                        dbds.SetValue("U_AuditorName", dbds.Offset, pVal.SelectedObjects.GetValue("jobTitle", 0).ToString());
                        break;
                    //费用
                    case "CFL_ItemCode":
                    case "CFL_ItemName":
                        dbds = CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_CCV2");
                        omtx = (SAPbouiCOM.Matrix)this.CurrentForm.Items.Item("mtx_1").Specific;
                        for (int i = 0; i < pVal.SelectedObjects.Rows.Count; i++)
                        {
                            dbds.Offset = SAPBoAddon.B1Assistant.Matrix.GetdbDsOffset(omtx, omtx.VisualRowCount, "col_f", dbds);
                            omtx.GetLineData(omtx.VisualRowCount);
                            dbds.SetValue("U_CostCode", dbds.Offset, pVal.SelectedObjects.GetValue("ItemCode", i).ToString());
                            dbds.SetValue("U_CostName", dbds.Offset, pVal.SelectedObjects.GetValue("ItemName", i).ToString());
                            dbds.SetValue("U_ForeignName", dbds.Offset, pVal.SelectedObjects.GetValue("FrgnName", i).ToString());
                            omtx.SetLineData(omtx.VisualRowCount);
                            SAPBoAddon.B1Assistant.Matrix.AutoAddNewLine(this.CurrentForm, "mtx_1", "col_f", "@AVA_FF_CCV2", omtx.VisualRowCount, "VisOrder", "VisOrder", true);
                        }
                        break;
                    //结算单位
                    case "CFL_CloseCode":
                    case "CFL_CloseName":
                        dbds = CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_CCV1");
                        omtx = (SAPbouiCOM.Matrix)this.CurrentForm.Items.Item("mtx_0").Specific;
                        dbds.Offset = SAPBoAddon.B1Assistant.Matrix.GetdbDsOffset(omtx, pVal.Row, "col_f", dbds);
                        omtx.GetLineData(pVal.Row);
                        dbds.SetValue("U_CardCode", dbds.Offset, pVal.SelectedObjects.GetValue("CardCode", 0).ToString());
                        dbds.SetValue("U_CardName", dbds.Offset, pVal.SelectedObjects.GetValue("CardName", 0).ToString());
                        dbds.SetValue("U_CardFName", dbds.Offset, pVal.SelectedObjects.GetValue("CardFName", 0).ToString());//added by WangPeng 2012-3-22
                        omtx.SetLineData(pVal.Row);
                        break;
                    //审核人
                    case "CFL_EmployeeC1":
                    case "CFL_EmployeeN1":
                        dbds = CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_CCV1");
                        omtx = (SAPbouiCOM.Matrix)this.CurrentForm.Items.Item("mtx_0").Specific;
                        dbds.Offset = SAPBoAddon.B1Assistant.Matrix.GetdbDsOffset(omtx, pVal.Row, "col_f", dbds);
                        omtx.GetLineData(pVal.Row);
                        dbds.SetValue("U_AuditorMan", dbds.Offset, pVal.SelectedObjects.GetValue("empID", 0).ToString());
                        dbds.SetValue("U_AuditorName", dbds.Offset, pVal.SelectedObjects.GetValue("jobTitle", 0).ToString());
                        omtx.SetLineData(pVal.Row);
                        break;
                    case "CFL_EmployeeC2":
                    case "CFL_EmployeeN2":
                        dbds = CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_CCV2");
                        omtx = (SAPbouiCOM.Matrix)this.CurrentForm.Items.Item("mtx_1").Specific;
                        dbds.Offset = SAPBoAddon.B1Assistant.Matrix.GetdbDsOffset(omtx, pVal.Row, "col_f", dbds);
                        omtx.GetLineData(pVal.Row);
                        dbds.SetValue("U_AuditorMan", dbds.Offset, pVal.SelectedObjects.GetValue("empID", 0).ToString());
                        dbds.SetValue("U_AuditorName", dbds.Offset, pVal.SelectedObjects.GetValue("jobTitle", 0).ToString());
                        omtx.SetLineData(pVal.Row);
                        break;
                }
            }
        }
        void B1Form_CreateVoucher_frm_ItemEvent(SAPBoAddon.B1AddonBase.B1ItemEvent pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {
                ////行审核
                //if (pVal.ColUID == "col_26" && (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED || pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK || pVal.ItemChanged))
                //{
                //    IsApprove(pVal.FormUID, pVal.ItemUID, pVal.Row, ref BubbleEvent);
                //}
                //单据审核
                if (pVal.ItemUID == "49" && (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED || pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK || pVal.ItemChanged))
                {
                    IsApprove(pVal.FormUID, ref BubbleEvent);
                }
                //数据添加之前
                if (pVal.ItemUID == "1" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    DataAdd(pVal.FormUID);
                }
                //设置Matrix行可以编辑
                if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_MATRIX_LOAD)
                {
                    Utils.SetMatrixRowEnable(this.CurrentForm, pVal.ItemUID);
                }
            }
            else
            {
                //计算应收与应付
                if ((pVal.ItemUID == "mtx_1" && pVal.ColUID == "col_11" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_LOST_FOCUS)
                    || pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_LOAD
                    || pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD
                    || pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_DELETE
                    || pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE
                    || pVal.EventType == SAPbouiCOM.BoEventTypes.et_DATASOURCE_LOAD
                    || pVal.EventType == SAPbouiCOM.BoEventTypes.et_MATRIX_LOAD)
                {
                    Sum(pVal.FormUID);
                }
                ////行审核
                //if (pVal.ColUID == "col_26" && (pVal.ItemChanged || pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK || pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED))
                //{
                //    IsApprove(pVal.FormUID, pVal.ItemUID, pVal.Row);
                //}
                //单据审核
                if (pVal.ItemUID == "49" && (pVal.ItemChanged || pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK || pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED))
                {
                    IsApprove(pVal.FormUID);
                }
                /*审核应收审核*/
                if ((pVal.ItemUID == "64" || pVal.ItemUID == "65") && (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED))
                {
                    this.AuditReceivePayLine(pVal.ItemUID);
                }
                ////设置Matrix行不可编辑
                //if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_MATRIX_LOAD)
                //{
                //    Utils.SetMatrixRowEnable(this.CurrentForm, pVal.ItemUID);
                //}
                if (pVal.ItemUID == "mtx_0" && pVal.ColUID == "col_f" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK)
                {
                    ClickMatrixRow(pVal.FormUID, pVal.Row);
                }
                /*费用单 LinkButton*/
                if (pVal.ItemUID == "mtx_1" && pVal.ColUID == "col_19" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_MATRIX_LINK_PRESSED)
                {
                    Utils.OpenUserDeFinedObjectForm(this.CurrentForm, pVal.ItemUID, pVal.ColUID, pVal.Row, "AVA_FF_CreateCost");
                }
                if (pVal.ItemUID == "CancelLine" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED)
                {
                    this.CancelConfirmBillLine();
                    this.ChangeCurrency();
                }
                /*账单币种选择*/
                if (pVal.ItemUID == "67" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_COMBO_SELECT)
                {
                    this.ChangeCurrency();
                }
                /*手动修改汇率*/
                if (pVal.ItemUID == "71" && pVal.ItemChanged && pVal.EventType == SAPbouiCOM.BoEventTypes.et_VALIDATE)
                {
                    this.ChangeCurrency(false);
                }
            }
        }
        void B1Form_CreateVoucher_frm_FormDataEvent(SAPBoAddon.B1AddonBase.B1BusinessObjectInfo pVal, ref bool BubbleEvent)
        {
            if (pVal.BeforeAction)
            {

            }
            else
            {
                if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_LOAD)
                {
                    #region 去除应收/应付审批的勾选
                    //this.CurrentForm.DataSources.UserDataSources.Item("AdtRece").Value = "N";
                    //this.CurrentForm.DataSources.UserDataSources.Item("AdtPay").Value = "N";
                    //this.CurrentForm.DataSources.UserDataSources.Item("AdtAll").Value = "N";
                    #endregion
                }
            }
        }

        #endregion

        #region 私有函数
        /// <summary>
        /// 计算应收与应付的差异
        /// </summary>
        private void Sum(string FormUID)
        {
            SAPbouiCOM.Form oForm;
            SAPbouiCOM.Matrix oMtx1;

            decimal sum = 0;

            oForm = SBOApp.Forms.Item(FormUID);
            oMtx1 = oForm.Items.Item("mtx_1").Specific;


            for (int i = 1; i <= oMtx1.VisualRowCount; i++)
            {
                sum += Decimal.Parse(SAPBoAddon.B1Assistant.Matrix.GetCellValue(oMtx1, "col_11", i).ToString());//费用金额
            }
            oForm.DataSources.UserDataSources.Item("Sum").Value = sum.ToString();

        }

        #region 审核
        /// <summary>
        /// 是否审核
        /// </summary>
        /// <param name="FormUID"></param>
        private void IsApprove(string FormUID, string MtxUID, int Row, ref bool BubbleEvent)
        {
            SAPbouiCOM.Form oForm;
            SAPbobsCOM.Recordset ors;
            SAPbouiCOM.Matrix oMtx;
            string TableName, DocEntry, Lineid;

            oForm = SBOApp.Forms.Item(FormUID);
            ors = SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            oMtx = oForm.Items.Item(MtxUID).Specific;
            TableName = oMtx.Columns.Item("col_f").DataBind.TableName;
            DocEntry = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "3").ToString();
            Lineid = SAPBoAddon.B1Assistant.Matrix.GetCellValue(oMtx, "col_f", Row, true).ToString();
            if (string.IsNullOrEmpty(SAPBoAddon.B1Assistant.Matrix.GetCellValue(oMtx, "col_26", Row).ToString()))
            {
                BubbleEvent = false;
            }
            ors.DoQuery("SELECT ISNULL(U_IsAudit,'N') Approve FROM [" + TableName + "] Where DocEntry = '" + DocEntry + "' And Lineid = '" + Lineid + "'");
            if (ors.RecordCount > 0)
            {
                if (ors.Fields.Item("Approve").Value.ToString() == "Y")
                {
                    SBOApp.SetStatusBarMessage("此项费用已审核，不允许进行修改！", SAPbouiCOM.BoMessageTime.bmt_Short, false);
                    BubbleEvent = false;
                }
            }
        }
        /// <summary>
        /// 单据审核
        /// </summary>
        /// <param name="FormUID"></param>
        /// <param name="BubbleEvent"></param>
        private void IsApprove(string FormUID, ref bool BubbleEvent)
        {
            SAPbouiCOM.Form oForm;
            SAPbobsCOM.Recordset ors;
            string DocEntry;

            oForm = SBOApp.Forms.Item(FormUID);
            if (oForm.Mode != SAPbouiCOM.BoFormMode.fm_OK_MODE)
            {
                SBOApp.SetStatusBarMessage("请保存单据，再进行审核操作！", SAPbouiCOM.BoMessageTime.bmt_Short, false);
                return;
            }
            ors = SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            DocEntry = SAPBoAddon.B1Assistant.Item.GetValue(oForm, "3").ToString();
            ors.DoQuery("SELECT ISNULL(U_IsAudit,'N') Approve FROM [@AVA_FF_OCCV] Where DocEntry = " + DocEntry);
            if (ors.RecordCount > 0)
            {
                if (ors.Fields.Item("Approve").Value.ToString() == "Y")
                {
                    SBOApp.SetStatusBarMessage("此项费用已审核，不允许进行修改！", SAPbouiCOM.BoMessageTime.bmt_Short, false);
                    BubbleEvent = false;
                }
            }

        }
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="FormUID"></param>
        /// <param name="MtxUID"></param>
        /// <param name="Row"></param>
        private void IsApprove(string FormUID, string MtxUID, int Row)
        {
            SAPbouiCOM.Form oForm;
            SAPbouiCOM.Matrix oMtx;
            string Selected = string.Empty;

            oForm = SBOApp.Forms.Item(FormUID);
            oMtx = oForm.Items.Item(MtxUID).Specific;
            Selected = SAPBoAddon.B1Assistant.Matrix.GetCellValue(oMtx, "col_26", Row).ToString();

            if (Selected == "Y")
            {
                oMtx.SetCellWithoutValidation(Row, "col_27", Utils.GetUserToEmployee(SBOCompany, SBOCompany.UserSignature).EmpID);
                oMtx.SetCellWithoutValidation(Row, "col_28", Utils.GetUserToEmployee(SBOCompany, SBOCompany.UserSignature).Name);
                oMtx.SetCellWithoutValidation(Row, "col_29", DateTime.Now.ToString("yyyyMMdd"));
            }
            else
            {
                oMtx.SetCellWithoutValidation(Row, "col_27", "");
                oMtx.SetCellWithoutValidation(Row, "col_28", "");
                oMtx.SetCellWithoutValidation(Row, "col_29", "");
            }
            #region 选中/取消选中 该单位下是所有费用项
            if (MtxUID == "mtx_0")
            {
                SAPbouiCOM.Matrix oMtx_FeeList = oForm.Items.Item("mtx_1").Specific;
                string LineId = SAPBoAddon.B1Assistant.Matrix.GetCellValue(oMtx, "col_LineId", Row).ToString().Trim();
                string ParentLineID = string.Empty;
                for (int FeeLineNum = 1; FeeLineNum <= oMtx_FeeList.VisualRowCount; FeeLineNum++)
                {
                    ParentLineID = SAPBoAddon.B1Assistant.Matrix.GetCellValue(oMtx_FeeList, "col_PLId", FeeLineNum).ToString().Trim();
                    if (ParentLineID == LineId)
                    {
                        oMtx_FeeList.SetCellWithoutValidation(FeeLineNum, "col_26", Selected);//"Y"
                    }
                }
            }
            #endregion
            oForm.Refresh();
        }
        /// <summary>
        /// 单据审核
        /// </summary>
        /// <param name="FormUID"></param>
        private void IsApprove(string FormUID)
        {
            SAPbouiCOM.Form oForm;
            SAPbouiCOM.DBDataSource dbds;
            string Selected = string.Empty;

            oForm = SBOApp.Forms.Item(FormUID);
            dbds = oForm.DataSources.DBDataSources.Item("@AVA_FF_OCCV");
            Selected = SAPBoAddon.B1Assistant.Item.GetValue(FormUID, "49").ToString();

            if (Selected == "Y")
            {
                dbds.SetValue("U_AuditorMan", dbds.Offset, Utils.GetUserToEmployee(SBOCompany, SBOCompany.UserSignature).EmpID);
                dbds.SetValue("U_AuditorName", dbds.Offset, Utils.GetUserToEmployee(SBOCompany, SBOCompany.UserSignature).Name);
                dbds.SetValue("U_AuditorDate", dbds.Offset, DateTime.Now.ToShortDateString());
                dbds.SetValue("U_Status", dbds.Offset, "R");//批准状态
            }
            else
            {
                dbds.SetValue("U_AuditorMan", dbds.Offset, "");
                dbds.SetValue("U_AuditorName", dbds.Offset, "");
                dbds.SetValue("U_AuditorDate", dbds.Offset, "");
                dbds.SetValue("U_Status", dbds.Offset, "P");//执行状态
            }
            #region 审核应收、应付里所有未审核的行 [2012-2-14 WangPeng]
            this.CurrentForm.DataSources.UserDataSources.Item("AdtRece").Value = Selected;
            this.CurrentForm.DataSources.UserDataSources.Item("AdtPay").Value = Selected;
            this.AuditReceivePayLine("64");
            this.AuditReceivePayLine("65");
            #endregion
            oForm.Refresh();
        }

        /// <summary>
        /// 审核应收/应付
        /// </summary>
        /// <author>WangPeng</author>
        private void AuditReceivePayLine(string ItemUID)
        {
            string MatrixUID = "mtx_0";
            string TableName = "@AVA_FF_CCV1";
            if (ItemUID == "65")
            {
                MatrixUID = "mtx_1";
                TableName = "@AVA_FF_CCV2";
            }
            SAPbobsCOM.Recordset oRst = SBOCompany.GetBusinessObject(BoObjectTypes.BoRecordset);
            List<string> List_AuditLines = new List<string>();
            string DocEntry = SAPBoAddon.B1Assistant.Item.GetValue(this.CurrentForm, "3").ToString();
            /*查找已审核的行*/
            string SQL_AuditLine = string.Format("SELECT LineId FROM [{0}] WHERE DocEntry={1} AND ISNULL(U_IsAudit,N'N')=N'Y' ", TableName, DocEntry);
            oRst.DoQuery(SQL_AuditLine);

            for (int i = 0; i < oRst.RecordCount; i++)
            {
                List_AuditLines.Add(oRst.Fields.Item("LineId").Value.ToString());
                oRst.MoveNext();
            }
            SAPbouiCOM.Matrix oMtx = this.CurrentForm.Items.Item(MatrixUID).Specific;
            string isCheck = SAPBoAddon.B1Assistant.Item.GetValue(CurrentForm.UniqueID, ItemUID).ToString();
            string LineId = string.Empty;
            SAPbouiCOM.DBDataSource dbds_CCT12 = this.CurrentForm.DataSources.DBDataSources.Item(TableName);
            for (int i = 0; i < dbds_CCT12.Size; i++)
            {
                dbds_CCT12.Offset = i;
                LineId = dbds_CCT12.GetValue("LineId", i).Trim();
                if (!List_AuditLines.Contains(LineId))
                {
                    dbds_CCT12.SetValue("U_IsAudit", i, isCheck);
                    oMtx.SetLineData(i + 1);
                }
            }
        }

        #endregion

        /// <summary>
        /// 单击Matrix的行，显示配码的数据
        /// </summary>
        private void ClickMatrixRow(string FormUID, int row)
        {
            SAPbouiCOM.Form oForm;
            SAPbouiCOM.Matrix oMtx1;
            SAPbouiCOM.Matrix oMtx2;
            SAPbouiCOM.DataTable dt;
            SAPbouiCOM.DBDataSource dbds1;
            SAPbouiCOM.DBDataSource dbds2;
            string BaseEntry;

            try
            {
                oForm = SBOApp.Forms.Item(FormUID);
                oMtx1 = oForm.Items.Item("mtx_0").Specific;
                oMtx2 = oForm.Items.Item("mtx_1").Specific;
                dbds1 = oForm.DataSources.DBDataSources.Item("@AVA_FF_CCV1");
                dbds2 = oForm.DataSources.DBDataSources.Item("@AVA_FF_CCV2");
                SAPBoAddon.B1Assistant.Matrix.UpdateDataTodbDataSource(oForm, oMtx2, dbds2, "col_f", "VisOrder");

                oMtx2.Clear();
                if (row == 0)
                {
                    oMtx2.LoadFromDataSource();
                    return;
                }

                BaseEntry = dbds1.GetValue("Lineid", SAPBoAddon.B1Assistant.Matrix.GetdbDsOffset(oMtx1, row, "col_f", dbds1));

                for (int j = 0; j <= dbds2.Size - 1; j++)
                {
                    dbds2.Offset = j;
                    if (dbds2.GetValue("U_ParentLineid", dbds2.Offset).Trim() == BaseEntry)
                    {
                        oMtx2.AddRow(1, j);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }

        private void DataAdd(string FormUID)
        {
            SAPbouiCOM.Form oForm;
            SAPbouiCOM.Matrix oMtx;


            oForm = SBOApp.Forms.Item(FormUID);

            oMtx = oForm.Items.Item("mtx_1").Specific;

            oMtx.LoadFromDataSource();
        }

        private void AddToParentForm(string ListFormUID, int FeeDocEntry, string SQL_LineIdIn)
        {
            SAPbouiCOM.Form oListForm;
            SAPbouiCOM.Grid oGrid;
            SAPbouiCOM.DBDataSource dbds;
            SAPbouiCOM.DBDataSource dbds1;
            SAPbouiCOM.Matrix oMtx1;
            SAPbouiCOM.DBDataSource dbds2;
            SAPbouiCOM.Matrix oMtx2;
            SAPbobsCOM.Recordset ors;
            SAPbobsCOM.Recordset ors2;
            int DocEntry;
            const string ct_BillType = " And U_BillType =N'{0}' ";
            string Condition_BillType = string.Empty;
            string AccountBPCode = string.Empty;/*结算单位*/
            string SQL_GetAccountBPList = string.Empty;/*结算单位列表*/
            string SQL_GetCostList = string.Empty;
            List<string> List_AccountBPCode = new List<string>();
            string SerialNum = SerialNumber.GetInstance().CreateSerialNumber(B1FormTypes.ado_AVA_FF_CreateVoucher).Remove(0, 1);
            decimal DocSum_RMB = 0;

            ors = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            ors2 = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            oListForm = SBOApp.Forms.Item(ListFormUID);
            oGrid = oListForm.Items.Item("CloseGrid").Specific;

            DocEntry = FeeDocEntry;

            if (SAPBoAddon.B1Assistant.Item.GetValue(oListForm, "12").ToString() == "Y")
            {
                Condition_BillType = string.Format(ct_BillType, "I");
                SerialNum = "D" + SerialNum;
            }
            else if (SAPBoAddon.B1Assistant.Item.GetValue(oListForm, "13").ToString() == "Y")
            {
                Condition_BillType = string.Format(ct_BillType, "O");
                SerialNum = "C" + SerialNum;
            }
            else
            {
                Condition_BillType = string.Empty;
            }
            dbds = CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_OCCV");
            dbds1 = CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_CCV1");
            oMtx1 = CurrentForm.Items.Item("mtx_0").Specific;
            dbds2 = CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_CCV2");
            oMtx2 = CurrentForm.Items.Item("mtx_1").Specific;
            #region 设置客户信息
            string FeeFormUID = oListForm.DataSources.UserDataSources.Item("ParentUID").Value;
            if (!string.IsNullOrEmpty(FeeFormUID))
            {
                SAPbouiCOM.Form FeeForm = SBOApp.Forms.Item(FeeFormUID);
                SAPbouiCOM.DBDataSource dbds_Fee = FeeForm.DataSources.DBDataSources.Item("@AVA_FF_OCCT");
                dbds.SetValue("U_CardCode", dbds.Offset, dbds_Fee.GetValue("U_CardCode", dbds_Fee.Offset).Trim());
                dbds.SetValue("U_CardName", dbds.Offset, dbds_Fee.GetValue("U_CardName", dbds_Fee.Offset).Trim());
                dbds.SetValue("U_BupEntry", dbds.Offset, dbds_Fee.GetValue("U_BaseEntry", dbds_Fee.Offset).Trim());
                dbds.SetValue("U_BupSerialNum", dbds.Offset, dbds_Fee.GetValue("U_BupSerialNum", dbds_Fee.Offset).Trim());
                dbds.SetValue("U_FeeEntry", dbds.Offset, dbds_Fee.GetValue("DocEntry", dbds_Fee.Offset).Trim());
                //dbds.SetValue("U_CntctCode", dbds.Offset, dt.GetValue("U_CntctCode", row));
                dbds.SetValue("U_SerialNum", dbds.Offset, SerialNum);
            }

            #endregion
            for (int i = 0; i < oGrid.Rows.SelectedRows.Count; i++)
            {
                AccountBPCode = oGrid.DataTable.GetValue("U_CardCode", oGrid.Rows.SelectedRows.Item(i, SAPbouiCOM.BoOrderType.ot_RowOrder));
                /*8.8 DI API 中Recordset还是不支持Distinct */
                SQL_GetAccountBPList = string.Format(@"SELECT Distinct U_BillType,U_CardCode,U_CardName,DocEntry FROM [@AVA_FF_CCTV] 
                Where ISNULL(U_VoucherEntry,N'N')=N'N' And DocEntry ={0} And U_CardCode =N'{1}' {2} AND U_Status=N'P' ", DocEntry, AccountBPCode, Condition_BillType);
                #region 加载结算单位
                ors.DoQuery(SQL_GetAccountBPList);
                for (int n = 0; n < ors.RecordCount; n++)
                {

                    if (List_AccountBPCode.Contains(AccountBPCode))
                    {
                        ors.MoveNext();
                        continue;
                    }
                    List_AccountBPCode.Add(AccountBPCode);
                    dbds1.Offset = SAPBoAddon.B1Assistant.Matrix.GetdbDsOffset(oMtx1, oMtx1.VisualRowCount, "col_f", dbds1);
                    oMtx1.GetLineData(oMtx1.VisualRowCount);
                    dbds1.SetValue("LineID", dbds1.Offset, oMtx1.VisualRowCount.ToString());
                    dbds1.SetValue("U_CardCode", dbds1.Offset, ors.Fields.Item("U_CardCode").Value);
                    dbds1.SetValue("U_CardName", dbds1.Offset, ors.Fields.Item("U_CardName").Value);
                    oMtx1.SetLineData(oMtx1.VisualRowCount);

                    SQL_GetCostList = string.Format(@"SELECT U_BillType,DocEntry,LineId,U_CostCode,U_CostName,U_ForeignName,U_CostDate,U_Currency,U_Quantity,U_Price,U_CostMoney,U_Rate,U_AmountRMB,U_CardCode,U_CardName "
                     + " FROM [@AVA_FF_CCTV] Where ISNULL(U_VoucherEntry,N'N')=N'N' And DocEntry ={0} And U_CardCode =N'{1}' {2}{3} AND U_Status=N'P' ", DocEntry, AccountBPCode, Condition_BillType, SQL_LineIdIn);
                    #region 加载费用
                    ors2.DoQuery(SQL_GetCostList);
                    for (int k = 0; k < ors2.RecordCount; k++)
                    {

                        dbds2.Offset = SAPBoAddon.B1Assistant.Matrix.GetdbDsOffset(oMtx2, oMtx2.VisualRowCount, "col_f", dbds2);
                        oMtx2.GetLineData(oMtx2.VisualRowCount);
                        dbds2.SetValue("U_ParentLineid", dbds2.Offset, dbds1.GetValue("Lineid", dbds1.Offset));
                        dbds2.SetValue("U_BillType", dbds2.Offset, ors2.Fields.Item("U_BillType").Value);
                        dbds2.SetValue("U_BaseEntry", dbds2.Offset, ors2.Fields.Item("DocEntry").Value);
                        dbds2.SetValue("U_BaseLineId", dbds2.Offset, ors2.Fields.Item("LineId").Value);
                        dbds2.SetValue("U_CostCode", dbds2.Offset, ors2.Fields.Item("U_CostCode").Value);
                        dbds2.SetValue("U_CostName", dbds2.Offset, ors2.Fields.Item("U_CostName").Value);
                        dbds2.SetValue("U_ForeignName", dbds2.Offset, ors2.Fields.Item("U_ForeignName").Value);
                        dbds2.SetValue("U_CostDate", dbds2.Offset, ors2.Fields.Item("U_CostDate").Value.ToString("yyyyMMdd"));
                        dbds2.SetValue("U_Currency", dbds2.Offset, ors2.Fields.Item("U_Currency").Value);
                        dbds2.SetValue("U_Quantity", dbds2.Offset, ors2.Fields.Item("U_Quantity").Value);
                        dbds2.SetValue("U_Price", dbds2.Offset, ors2.Fields.Item("U_Price").Value);
                        dbds2.SetValue("U_CostMoney", dbds2.Offset, ors2.Fields.Item("U_CostMoney").Value);
                        dbds2.SetValue("U_Rate", dbds2.Offset, ors2.Fields.Item("U_Rate").Value);
                        dbds2.SetValue("U_AmountRMB", dbds2.Offset, ors2.Fields.Item("U_AmountRMB").Value);

                        DocSum_RMB += Convert.ToDecimal(ors2.Fields.Item("U_AmountRMB").Value); /*单据总计  默认RMB*/

                        oMtx2.SetLineData(oMtx2.VisualRowCount);

                        if (k < ors2.RecordCount - 1)/*最后不插入一空行 added by WangPeng 2012-3-23*/
                        {
                            SAPBoAddon.B1Assistant.Matrix.AutoAddNewLine(CurrentForm, "mtx_1", "col_f", "@AVA_FF_CCV2", oMtx2.VisualRowCount, "VisOrder", "VisOrder", true);
                        }

                        ors2.MoveNext();
                    }
                    #endregion
                    if (n < ors.RecordCount - 1)/*最后不插入一空行 added by WangPeng 2012-3-23*/
                    {
                        SAPBoAddon.B1Assistant.Matrix.AutoAddNewLine(CurrentForm, "mtx_0", "col_f", "@AVA_FF_CCV1", oMtx1.VisualRowCount, "VisOrder", "VisOrder", true);
                    }

                    ors.MoveNext();
                }
                #endregion
            }
            dbds.SetValue("U_Currency", dbds.Offset, "RMB");
            dbds.SetValue("U_Rate", dbds.Offset, "1.0");
            dbds.SetValue("U_DocSum", dbds.Offset, DocSum_RMB.ToString());
            oListForm.Close();
        }

        /// <summary>
        /// 作废行
        /// </summary>
        /// <author>WangPeng</author>
        private void CancelConfirmBillLine()
        {
            SAPbobsCOM.Recordset oRst = SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            SAPbouiCOM.Matrix oMtx = this.CurrentForm.Items.Item("mtx_1").Specific;
            int SelectRow = oMtx.GetNextSelectedRow();
            string SQL_CancelLine = string.Empty;
            string DocEntry = SAPBoAddon.B1Assistant.Item.GetValue(this.CurrentForm, "3").ToString().Trim();
            string LineId = string.Empty;
            List<int> List_LineId = new List<int>();
            if (this.CurrentForm.Mode == SAPbouiCOM.BoFormMode.fm_ADD_MODE)
            {
                SBOApp.StatusBar.SetText("账单未添加，无须作废对账单行.", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
                return;
            }
            if (SelectRow < 0)
            {
                SBOApp.StatusBar.SetText("请选中[费用信息]中需要作废的行.", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
                return;
            }
            while (SelectRow > 0)
            {
                List_LineId.Add(SelectRow);
                LineId = SAPBoAddon.B1Assistant.Matrix.GetCellValue(oMtx, "col_f", SelectRow).ToString().Trim();
                SQL_CancelLine += string.Format("EXEC AVA_SC_CancelVoucherLine {0},{1};", DocEntry, LineId);
                SelectRow = oMtx.GetNextSelectedRow(SelectRow);
            }
            if (!string.IsNullOrEmpty(SQL_CancelLine))
            {
                oRst.DoQuery(SQL_CancelLine);
                foreach (int row in List_LineId)
                {
                    oMtx.SelectRow(row, false, false);
                    oMtx.DeleteRow(row);
                }
                SBOApp.StatusBar.SetText("操作成功.", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success);
            }

        }
        /// <summary>
        /// 选择账单币种
        /// </summary>
        /// <author>WangPeng</author>
        private void ChangeCurrency(bool isChangeRate = true)
        {
            string SelectCurrency = SAPBoAddon.B1Assistant.Item.GetValue(this.CurrentForm, "67").ToString().Trim();
            SAPbouiCOM.Matrix oMtx_1 = this.CurrentForm.Items.Item("mtx_1").Specific;
            SAPbouiCOM.DBDataSource dbds_OCCV = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_OCCV");
            SAPbouiCOM.DBDataSource dbds_CCV2 = this.CurrentForm.DataSources.DBDataSources.Item("@AVA_FF_CCV2");
            decimal DocRate = Convert.ToDecimal(dbds_OCCV.GetValue("U_Rate", dbds_OCCV.Offset));
            decimal LineCost = 0;
            decimal LineRate = 0;
            decimal LineDocCurrency = 0;
            decimal DocSum = 0;
            if (isChangeRate)
            {
                DocRate = Utils.GetRateByCurrency(SelectCurrency);
                dbds_OCCV.SetValue("U_Rate", dbds_OCCV.Offset, DocRate.ToString());
            }

            oMtx_1.FlushToDataSource();
            for (int offset = 0; offset < dbds_CCV2.Size; offset++)
            {
                dbds_CCV2.Offset = offset;
                LineCost = Convert.ToDecimal(dbds_CCV2.GetValue("U_CostMoney", offset).Trim());
                LineRate = Convert.ToDecimal(dbds_CCV2.GetValue("U_Rate", offset).Trim());
                LineDocCurrency = LineCost * LineRate /DocRate;
                dbds_CCV2.SetValue("U_AmountRMB", offset, LineDocCurrency.ToString());
                DocSum += LineDocCurrency;
            }
            dbds_OCCV.SetValue("U_DocSum", dbds_OCCV.Offset, DocSum.ToString());
            oMtx_1.LoadFromDataSourceEx();
        }
        #endregion
    }
}
